import {Page} from '@/base/Page';
import {Role} from '@/base/model/Role';
import {getRoleList} from '@/base/api/RoleApi';

export class RoleSelectorBloc {

  paged: Page<Role> = new Page<Role>([], 0, 1, 15, 0, []);
  loading = false;

  load(name: string, companyId: number) {
    this.loading = true;
    const obj: any = {
      pageIndex: 1,
      pageSize: 50,
      name
    };
    if (companyId !== 0) obj.companyId = [companyId];
    return getRoleList(obj).then((res) => {
      console.log(this.paged);
      this.paged = res.data;
    }).finally(() => {
      this.loading = false;
    });
  }
}
